package com.scholarship.modules.admin.mapper;

import com.scholarship.common.config.MapResultHandler;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 查询两列数据，一列为key，一类为value
 * 用于sqlSession查询
 * @Author Z.J.H
 * @create 2021/9/11 19:40
 */
@Repository
public class MapSessionMapper extends SqlSessionDaoSupport {

    @Resource
    @Override
    public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
        super.setSqlSessionFactory(sqlSessionFactory);
    }

    /**
     * 通过tableId查询Map<选项名，得分>
     * @param tableId
     * @return
     */
    public Map<String,Double> listOptionScoreMapBytableId(Integer tableId) {
        MapResultHandler handler = new MapResultHandler();
        this.getSqlSession().select(ADropDownBoxMapper.class.getName() + ".listOptionScoreMapBytableId",tableId,handler);
        Map<String,Double> map = handler.getMappedResults();

        return map;
    }

    /**
     * 查询Map<状态名，状态id>
     * @return
     */
    public Map<String,Integer> listStateNameIdMap() {
        MapResultHandler handler = new MapResultHandler();
        this.getSqlSession().select(ARewardFeedbackMapper.class.getName() + ".listStateNameIdMap",handler);
        Map<String,Integer> map = handler.getMappedResults();

        return map;
    }
}
